/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejemploswing1;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 *
 * @author rosa
 */
public class MiSwing extends JFrame implements ActionListener{
    private JLabel etiqueta;
    private JButton boton,botonb;
    private JFrame marco;
    private JPanel panel; 
    public MiSwing() {
        marco=new JFrame("Mi primer marco");
       // marco.setTitle("Hola");
       marco.setSize(600,500);
       panel=new JPanel();
       marco.add(panel);
       panel.setBackground(Color.GREEN);
       marco.setVisible(true);
       marco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       etiqueta=new JLabel ("hola")  ;
       panel.add(etiqueta);
       boton=new JButton("pulsa");
       botonb=new JButton("cambia color");
       panel.add(boton);
       panel.add(botonb);
       //poner un escuchador
       boton.addActionListener(this);
       botonb.addActionListener(this);
       }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==boton){
            if(etiqueta.getText().equalsIgnoreCase("hola"))
                etiqueta.setText("adios");
            else
                etiqueta.setText("hola");
        }
        else if(e.getSource()==botonb){
            if(panel.getBackground()==Color.GREEN)
                panel.setBackground(Color.red);
            else
                panel.setBackground(Color.GREEN);
        }
    }

   
    
}
